<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here

// as we are now within the tab box, we have to state (call) the needed information saved in the variables of the parent function
GLOBAL $AppUI, $canRead, $canEdit, $m, $tab;
require_once(DP_BASE_DIR."/modules/masterdata/mdstatus.class.php");
if (!$canRead) {			// lock out users that do not have at least readPermission on this module
	$AppUI->redirect( "m=public&a=access_denied" );
}
$active = intval( dPgetParam( $_REQUEST, 'active', 1 ) );
$type =  $_REQUEST['stype'];
$stypes = array_merge(array(''=>$AppUI->_('--Select Type--')),$status_types);

//prepare an html table with a head section
?>
<table class="infopanel" width="100%" cellspacing="0" cellpadding="7" border="0">
<tr>
	<td colspan="100%"><input type="button" class="button" onClick="doEditStatus(0)" value="<?php echo $AppUI->_( 'New status' );?>"/></td>
	<td align="right" nowrap>
		<form name="MdStatusFilter" action="?m=<?=$m?>&tab=<?=$tab?>" method="post">
			<?= arraySelect($stypes,'stype','style="font-size:10px" onchange="this.form.submit()"',$type)?>
			<input  class="button" onclick ="this.form.submit()" type="radio" name="active" value="-1" <?php if ($active == -1) echo "checked" ?> /><?=$AppUI->_('All')?>
			<input  class="button" onclick ="this.form.submit()" type="radio" name="active" value="1" <?php if ($active == 1) echo "checked" ?> /> <?=$AppUI->_('Active') ?>
			<input  class="button" onclick ="this.form.submit()" type="radio" name="active" value="0" <?php if ($active == '0') echo "checked" ?> /> <?=$AppUI->_('Disable')?>
		</form>
	</td>
</tr>
</table>
<table id="idTableMasterdata" class="list" width="100%" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>
	<th nowrap="nowrap">&nbsp;</th>
	<!--th nowrap="nowrap"><?php echo $AppUI->_( 'Code' );?></th-->
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Name' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Type' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Active' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Delete' );?></th>

</tr>

<?php
// retrieving some dynamic content using an easy database query
$q = new DBQuery();
$q->addTable('md_status');
$q->addQuery('*');

if($active>-1){
	$q->addWhere('status_active = '.$active);
}
if($type!= null && $type!=''){
	$q->addWhere('status_type= "'.$type.'"');
}
$q->addOrder('status_name');
//echo $q->prepare();
$status = $q->loadList();		// retrieve a list (in form of an indexed array) of einstein quotes via an abstract db method

// add/show now gradually the einstein quotes
if (empty($status)) {?>
<tr class="second">
<td colspan="100"><?=$AppUI->_( 'No item available' );?></td>
</tr>
<?php
}
$i = 0;
foreach ($status as $row) {		//parse the array of einstein quotes
	$i++;
?>
<tr class="<?=($i % 2 == 0) ? "second" : "first" ?>">
	<td nowrap="nowrap" width="20">


	<?php if ($canEdit) {	// in case of writePermission on the module show an icon providing edit functionality for the given quote item

		// call the edit site with the unique id of the quote item

		// use the dPFrameWork to show the image
		// always use this way via the framework instead of hard code for the advantage
		// of central improvement of code in case of bugs etc. and for other reasons
		//echo "\n".'<a href="./index.php?m=masterdata&a=mdstatus_edit&status_id=' . $row["status_id"] . '">Test</a>';
		echo "\n".'<a onclick="doEditStatus('.$row["status_id"]. ')">';
		echo dPshowImage( 'images/edit.gif' );
		echo "\n</a>";
	}
	?>
	</td>
	<!--td >
	<?php
	echo $row["status_code"];		// finally show the einstein quote stored in the indexed array
	?>
	</td-->
	<td >
	<?php
	echo $row["status_name"];		// finally show the einstein quote stored in the indexed array
	?>
	</td>
	<td >
	<?php
	echo $row["status_type"];		// finally show the einstein quote stored in the indexed array
	?>
	</td>
	<td ><?php if($row["status_active"]==1){ echo dPshowImage( 'images/tick.gif' );}?></td>
	<td>
	<?php if ($canEdit) {
		showIconLink('images/delete.gif', 'js:doDelete('.$row["status_id"]. ', \''.$row["status_name"].'\')', 'Delete');
	}
	?>
	</td>
</tr>
<?php
}
?>
</tbody>
</table>
<div id="idStatusDialog" class="popup" style="visibility: hidden; left: 436px; top: 94.5px; display: none;">
</div>

<script type="text/javascript" language="javascript">
	Table("idTableMasterdata").setNormalHover(1);
</script>
<form name="MdFormDelete" id="MdFormDelete" method="post">
	<input type="hidden" name="dosql" value ="mdstatus_do_delete" />
	<input type="hidden" name="m" value ="masterdata" />
	<input type="hidden" id="del_cc_id" name="status_id" value ="" />
	<input type="hidden" name="del" value ="" />
</form>